package com.bocom.dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import com.bocom.entity.Users;

//@Repository
public class UsersDao {
	
//	@Resource
	private SessionFactory sessionFactory;
	
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }
    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }
    
	public Users selectByUsername(String username) {
		
		if (username.isEmpty()==false) {
			
			String hsql="from yhxx where username=:username";
			Query query = sessionFactory.getCurrentSession().createQuery(hsql);
			query.setString("username", username);
			@SuppressWarnings("unchecked")
			List<Users> ulist = query.list();
			if (ulist.size()>0){
//			System.out.println("sessionFactory username="+ulist.get(0).getUsername());
//			System.out.println("sessionFactory username="+ulist.get(0).getPassword());		
			return ulist.get(0);
			
			}			
		}
		return null;
	}	
	
}
